package android.skin.change

import android.os.Bundle
import android.skin.change.loader.CustomSDCardLoader
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.SkinAppCompatDelegateImpl
import skin.support.SkinCompatManager

class MainActivity : AppCompatActivity() {
    private var change = false
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //创建一下皮肤包存储地址
        val externalFilesDir = getExternalFilesDir("skins")

        setContentView(R.layout.activity_main)
        val tvShow = findViewById<TextView>(R.id.tvShow)
        tvShow.setOnClickListener {
            change = !change
            if (change)
                SkinCompatManager.getInstance()
                    .loadSkin("night", SkinCompatManager.SKIN_LOADER_STRATEGY_BUILD_IN) // 后缀加载
//                SkinCompatManager.getInstance().loadSkin("blue.skin", SkinCompatManager.SKIN_LOADER_STRATEGY_ASSETS) // assets加载
//                SkinCompatManager.getInstance().loadSkin(
//                    "blue.skin",
//                    CustomSDCardLoader.SKIN_LOADER_STRATEGY_SDCARD
//                ) // sd卡路径加载
            else
                SkinCompatManager.getInstance().restoreDefaultTheme()

        }
    }

    override fun getDelegate(): AppCompatDelegate {
        return SkinAppCompatDelegateImpl.get(this, this)
    }
}